package uniandes.dermatologia;

import uniandes.dermatologia.models.Anamnesis.Phototypes;
import uniandes.dermatologia.singleton.DermatologiaUniandesApp;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;

public class PhototypeActivity extends Activity {

	RadioButton radioButtonPhototype1;
	RadioButton radioButtonPhototype2;
	RadioButton radioButtonPhototype3;
	RadioButton radioButtonPhototype4;
	RadioButton radioButtonPhototype5;
	RadioButton radioButtonPhototype6;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_phototype);

		Button btnBack = (Button) findViewById(R.id.btnBackPhototype);
		Button btnNext = (Button) findViewById(R.id.btnNextPhototype);
		
		Typeface font = Typeface.createFromAsset(getAssets(),
				"fonts/Roboto-Light.ttf");

		btnBack.setTypeface(font);
		btnNext.setTypeface(font);
		
		getActionBar().setDisplayHomeAsUpEnabled(false);
		
		radioButtonPhototype1 = (RadioButton) findViewById(R.id.radioPhototypeI);
		radioButtonPhototype2 = (RadioButton) findViewById(R.id.radioPhototypeII);
		radioButtonPhototype3 = (RadioButton) findViewById(R.id.radioPhototypeIII);
		radioButtonPhototype4 = (RadioButton) findViewById(R.id.radioPhototypeIV);
		radioButtonPhototype5 = (RadioButton) findViewById(R.id.radioPhototypeV);
		radioButtonPhototype6 = (RadioButton) findViewById(R.id.radioPhototypeVI);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.phototype, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			// This ID represents the Home or Up button. In the case of this
			// activity, the Up button is shown. Use NavUtils to allow users
			// to navigate up one level in the application structure. For
			// more details, see the Navigation pattern on Android Design:
			//
			// http://developer.android.com/design/patterns/navigation.html#up-vs-back
			//
			NavUtils.navigateUpFromSameTask(this);
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	public void onClickPhototypeI(View v) {
		if (radioButtonPhototype2.isChecked()) {
			radioButtonPhototype2.setChecked(false);
		}
		if (radioButtonPhototype3.isChecked()) {
			radioButtonPhototype3.setChecked(false);
		}
		if (radioButtonPhototype4.isChecked()) {
			radioButtonPhototype4.setChecked(false);
		}
		if (radioButtonPhototype5.isChecked()) {
			radioButtonPhototype5.setChecked(false);
		}
		if (radioButtonPhototype6.isChecked()) {
			radioButtonPhototype6.setChecked(false);
		}
	}

	public void onClickPhototypeII(View v) {
		if (radioButtonPhototype1.isChecked()) {
			radioButtonPhototype1.setChecked(false);
		}
		if (radioButtonPhototype3.isChecked()) {
			radioButtonPhototype3.setChecked(false);
		}
		if (radioButtonPhototype4.isChecked()) {
			radioButtonPhototype4.setChecked(false);
		}
		if (radioButtonPhototype5.isChecked()) {
			radioButtonPhototype5.setChecked(false);
		}
		if (radioButtonPhototype6.isChecked()) {
			radioButtonPhototype6.setChecked(false);
		}
	}

	public void onClickPhototypeIII(View v) {
		if (radioButtonPhototype1.isChecked()) {
			radioButtonPhototype1.setChecked(false);
		}
		if (radioButtonPhototype2.isChecked()) {
			radioButtonPhototype2.setChecked(false);
		}
		if (radioButtonPhototype4.isChecked()) {
			radioButtonPhototype4.setChecked(false);
		}
		if (radioButtonPhototype5.isChecked()) {
			radioButtonPhototype5.setChecked(false);
		}
		if (radioButtonPhototype6.isChecked()) {
			radioButtonPhototype6.setChecked(false);
		}
	}

	public void onClickPhototypeIV(View v) {
		if (radioButtonPhototype1.isChecked()) {
			radioButtonPhototype1.setChecked(false);
		}
		if (radioButtonPhototype2.isChecked()) {
			radioButtonPhototype2.setChecked(false);
		}
		if (radioButtonPhototype3.isChecked()) {
			radioButtonPhototype3.setChecked(false);
		}
		if (radioButtonPhototype5.isChecked()) {
			radioButtonPhototype5.setChecked(false);
		}
		if (radioButtonPhototype6.isChecked()) {
			radioButtonPhototype6.setChecked(false);
		}
	}

	public void onClickPhototypeV(View v) {
		if (radioButtonPhototype1.isChecked()) {
			radioButtonPhototype1.setChecked(false);
		}
		if (radioButtonPhototype2.isChecked()) {
			radioButtonPhototype2.setChecked(false);
		}
		if (radioButtonPhototype3.isChecked()) {
			radioButtonPhototype3.setChecked(false);
		}
		if (radioButtonPhototype4.isChecked()) {
			radioButtonPhototype4.setChecked(false);
		}
		if (radioButtonPhototype6.isChecked()) {
			radioButtonPhototype6.setChecked(false);
		}
	}

	public void onClickPhototypeVI(View v) {
		if (radioButtonPhototype1.isChecked()) {
			radioButtonPhototype1.setChecked(false);
		}
		if (radioButtonPhototype2.isChecked()) {
			radioButtonPhototype2.setChecked(false);
		}
		if (radioButtonPhototype3.isChecked()) {
			radioButtonPhototype3.setChecked(false);
		}
		if (radioButtonPhototype4.isChecked()) {
			radioButtonPhototype4.setChecked(false);
		}
		if (radioButtonPhototype5.isChecked()) {
			radioButtonPhototype5.setChecked(false);
		}
	}

	public void onClickNext(View v) {
		if (radioButtonPhototype1.isChecked()) {
			((DermatologiaUniandesApp) getApplication())
					.getCurrentConsultation().getAnamnesis()
					.setPhototypes(Phototypes.PHOTOTYPE_I);
			startNextActivity();
		} else if (radioButtonPhototype2.isChecked()) {
			((DermatologiaUniandesApp) getApplication())
					.getCurrentConsultation().getAnamnesis()
					.setPhototypes(Phototypes.PHOTOTYPE_II);
			startNextActivity();
		} else if (radioButtonPhototype3.isChecked()) {
			((DermatologiaUniandesApp) getApplication())
					.getCurrentConsultation().getAnamnesis()
					.setPhototypes(Phototypes.PHOTOTYPE_III);
			startNextActivity();
		} else if (radioButtonPhototype4.isChecked()) {
			((DermatologiaUniandesApp) getApplication())
					.getCurrentConsultation().getAnamnesis()
					.setPhototypes(Phototypes.PHOTOTYPE_IV);
			startNextActivity();
		} else if (radioButtonPhototype5.isChecked()) {
			((DermatologiaUniandesApp) getApplication())
					.getCurrentConsultation().getAnamnesis()
					.setPhototypes(Phototypes.PHOTOTYPE_V);
			startNextActivity();
		} else if (radioButtonPhototype6.isChecked()) {
			((DermatologiaUniandesApp) getApplication())
					.getCurrentConsultation().getAnamnesis()
					.setPhototypes(Phototypes.PHOTOTYPE_VI);
			startNextActivity();
		} else {
			AlertDialog ad = new AlertDialog.Builder(this).create();
			ad.setCancelable(false);
			ad.setTitle(R.string.suggestion);
			ad.setMessage(getString(R.string.phototype_error));
			ad.setButton(DialogInterface.BUTTON_NEUTRAL,
					getString(R.string.close_alert_dialog),
					new DialogInterface.OnClickListener() {
						@Override
						public void onClick(DialogInterface dialog, int which) {
							dialog.dismiss();
						}
					});
			ad.show();
		}
	}

	public void startNextActivity() {
		Intent intent = new Intent(this, LesionTypeActivity.class);
		// Intent intent = new Intent(this, BodyActivity.class);
		startActivity(intent);
	}

	public void onClickBack(View v) {
		finish();
	}
}
